-- DAV_CTRL.VHD (a peripheral module for SCOMP)
-- 2006.10.08
--
-- This module drives the UP3 board DAC independent of the switch and latches data on the rising edge of CS.


LIBRARY IEEE;
LIBRARY LPM;

USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE LPM.LPM_COMPONENTS.ALL;


ENTITY AUDIO_CTRL IS
  PORT(
    RESETN      : IN  STD_LOGIC;
    CS          : IN  STD_LOGIC;
    DAC_CTRL    : OUT STD_LOGIC
  );
END AUDIO_CTRL;


ARCHITECTURE a OF AUDIO_CTRL IS
  SIGNAL DAC_CTRL_EN : STD_LOGIC;

  BEGIN
    DAC_CTRL <= DAC_CTRL_EN;


    PROCESS (RESETN, CS)
      BEGIN
        IF (RESETN = '0') THEN
          DAC_CTRL_EN <= '0';
        ELSIF (RISING_EDGE(CS)) THEN
          DAC_CTRL_EN <= NOT DAC_CTRL_EN;
        END IF;
      END PROCESS;
  END a;